package com.fdb.efp.nls.service.impl.sx;

import com.alibaba.fastjson.JSON;
import com.fdb.efp.nls.service.domain.sx.NlsCreditInfo;
import com.fdb.efp.nls.service.facade.sx.NlsCreditInfoService;
import com.fdb.efp.nls.service.vo.sx.NlsCreditInfoVO;
import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.basic.framework.core.bean.SedSynCusManageVO;
import com.fdb.basic.framework.core.exception.BizException;
import com.fdb.efp.nls.service.dao.sx.NlsCreditInfoDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 网贷授信申请表				<p>
 * @author ligm
 * @date 2019-03-04
 */
@Service("nlsCreditInfoService")
public class NlsCreditInfoServiceImpl implements NlsCreditInfoService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(NlsCreditInfoServiceImpl.class);

	@Autowired
	private NlsCreditInfoDao nlsCreditInfoDao;
	
	/**
	 * 新增操作
	 */
	public int insertNlsCreditInfo(NlsCreditInfoVO inNlsCreditInfoVo) {
		logger.debug("当前新增数据为:"+ inNlsCreditInfoVo.toString());
		int num = 0;
		try {
			NlsCreditInfo nlsCreditInfo = new NlsCreditInfo();
			beanCopy(inNlsCreditInfoVo, nlsCreditInfo);
			num = nlsCreditInfoDao.insertNlsCreditInfo(nlsCreditInfo);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(NlsCreditInfoVO inNlsCreditInfoVo) {
		logger.debug("当前删除数据条件为:"+ inNlsCreditInfoVo);
		int num = 0;
		try {
			NlsCreditInfo nlsCreditInfo = new NlsCreditInfo();
			beanCopy(inNlsCreditInfoVo, nlsCreditInfo);
			num = nlsCreditInfoDao.deleteByPk(nlsCreditInfo);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inNlsCreditInfoVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(NlsCreditInfoVO inNlsCreditInfoVo) {
		logger.debug("当前修改数据为:"+ inNlsCreditInfoVo.toString());
		int num = 0;
		try {
			NlsCreditInfo nlsCreditInfo = new NlsCreditInfo();
			beanCopy(inNlsCreditInfoVo, nlsCreditInfo);
			num = nlsCreditInfoDao.updateByPk(nlsCreditInfo);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inNlsCreditInfoVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public NlsCreditInfoVO queryByPk(NlsCreditInfoVO inNlsCreditInfoVo) {
		
		logger.debug("当前查询参数信息为:"+ inNlsCreditInfoVo);
		try {
			NlsCreditInfo queryNlsCreditInfo = new NlsCreditInfo();
			beanCopy(inNlsCreditInfoVo, queryNlsCreditInfo);
			NlsCreditInfo queryRslNlsCreditInfo = nlsCreditInfoDao.queryByPk(queryNlsCreditInfo);
			if (Objects.nonNull(queryRslNlsCreditInfo)) {
				NlsCreditInfoVO outNlsCreditInfoVo = beanCopy(queryRslNlsCreditInfo, new NlsCreditInfoVO());
				logger.debug("当前查询结果为:"+ outNlsCreditInfoVo.toString());
				return outNlsCreditInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}
	
	/**
	 * 根据流水号以及百度reqSn判断
	 */
	public NlsCreditInfoVO queryCopy(NlsCreditInfoVO inNlsCreditInfoVo) {

		logger.debug("当前查询参数信息为:"+ inNlsCreditInfoVo);
		try {
			NlsCreditInfo queryNlsCreditInfo = new NlsCreditInfo();
			beanCopy(inNlsCreditInfoVo, queryNlsCreditInfo);
			NlsCreditInfo queryRslNlsCreditInfo = nlsCreditInfoDao.queryCopy(queryNlsCreditInfo);
			if (Objects.nonNull(queryRslNlsCreditInfo)) {
				NlsCreditInfoVO outNlsCreditInfoVo = beanCopy(queryRslNlsCreditInfo, new NlsCreditInfoVO());
				logger.debug("当前查询结果为:"+ outNlsCreditInfoVo.toString());
				return outNlsCreditInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<NlsCreditInfoVO> queryAllOwner(NlsCreditInfoVO nlsCreditInfoVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<NlsCreditInfoVO> list = null;
		try {
			List<NlsCreditInfo> nlsCreditInfos = nlsCreditInfoDao.queryAllOwnerByPage(nlsCreditInfoVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ nlsCreditInfos.size());
			pageSet(nlsCreditInfos, nlsCreditInfoVo);
			list = (List<NlsCreditInfoVO>) beansCopy(nlsCreditInfos, NlsCreditInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<NlsCreditInfoVO> queryAllCurrOrg(NlsCreditInfoVO nlsCreditInfoVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<NlsCreditInfo> nlsCreditInfos = nlsCreditInfoDao.queryAllCurrOrgByPage(nlsCreditInfoVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+nlsCreditInfos.size());
		List<NlsCreditInfoVO> list = null;
		try {
			pageSet(nlsCreditInfos, nlsCreditInfoVo);
			list = (List<NlsCreditInfoVO>) beansCopy(nlsCreditInfos, NlsCreditInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<NlsCreditInfoVO> queryAllCurrDownOrg(NlsCreditInfoVO nlsCreditInfoVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<NlsCreditInfo> nlsCreditInfos = nlsCreditInfoDao.queryAllCurrDownOrgByPage(nlsCreditInfoVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ nlsCreditInfos.size());
		List<NlsCreditInfoVO> list = null;
		try {
			pageSet(nlsCreditInfos, nlsCreditInfoVo);
			list = (List<NlsCreditInfoVO>) beansCopy(nlsCreditInfos, NlsCreditInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}

	/**
	 * 查询当前产品种类权限数据
	 * @param nlsCreditInfoVo
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<NlsCreditInfoVO> queryAllCurrOwnerPrd(NlsCreditInfoVO nlsCreditInfoVo) {
		logger.debug("当前产品种类数据信息的参数信息为:");
		List<NlsCreditInfo> nlsCreditInfos = nlsCreditInfoDao.queryAllCurrOwnerPrdByPage(nlsCreditInfoVo);
		logger.debug("当前产品种类数据信息的结果集数量为:"+ nlsCreditInfos.size());
		List<NlsCreditInfoVO> list = null;
		try {
			pageSet(nlsCreditInfos, nlsCreditInfoVo);
			list = (List<NlsCreditInfoVO>) beansCopy(nlsCreditInfos, NlsCreditInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;

	}

	/**
	 * 查询当前客户是否存在进件申请
	 */
	@Override
	@SuppressWarnings("unchecked")
	public List<NlsCreditInfoVO> queryCertCode(NlsCreditInfoVO nlsCreditInfoVO) {
		logger.debug("查询当前客户是否存在进件申请:");
		List<NlsCreditInfoVO> nlsCreditInfos = nlsCreditInfoDao.queryCertCode(nlsCreditInfoVO);
		logger.debug("查询当前客户是否存在进件申请:" + nlsCreditInfos.size());
		List<NlsCreditInfoVO> list = null;
		try {
			list = (List<NlsCreditInfoVO>) beansCopy(nlsCreditInfos, NlsCreditInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}
	
	/**
	 * 
	 * 同步授信申请正式表有数据则更新，无则新增 <br>
	 * 0.1:ludayong:2019年5月10日 下午3:35:56:新增 <br>
	 * 
	 * @author ludayong
	 * @since 2019年5月10日 下午3:35:56
	 * @date 2019年5月10日 下午3:35:56
	 * @version 0.1
	 */
	@SuppressWarnings("unchecked")
	@Override
	public int insertOrUpdateNlsCreditInfo(List<NlsCreditInfoVO> list) {
		LocalDate today = LocalDate.now();
		String msg1 = "【授信申请正式表】数据同步开始..." + today;
		logger.info(msg1, "message{}");
		List<NlsCreditInfo> nlsCreditInfoList = new ArrayList<NlsCreditInfo>();
		int num = 0;
		try {
			nlsCreditInfoList = (List<NlsCreditInfo>) beansCopy(list, NlsCreditInfo.class);
			num = nlsCreditInfoDao.insertOrUpdateNlsCreditInfo(nlsCreditInfoList);
			String num_msg = "【授信申请正式表】插入或更新数据处理结果:" + num;
			logger.info(num_msg, "message{}");
		} catch (Exception e) {
			String msg2 = "【授信申请正式表】插入或更新数据出现异常:" + e;
			logger.error(msg2, "message{}");
			num = -1;
		}
		finally {
			list = null;
			nlsCreditInfoList = null;
		}
		return num;
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<NlsCreditInfoVO> queryAllByCondition(NlsCreditInfoVO nlsCreditInfoVo) {
		logger.debug("按条件查询所有信息:");
		List<NlsCreditInfo> nlsCreditInfos = nlsCreditInfoDao.queryAllByCondition(nlsCreditInfoVo);
		logger.debug("按条件查询所有信息的结果集数量为:"+ nlsCreditInfos.size());
		List<NlsCreditInfoVO> list = null;
		try {
			pageSet(nlsCreditInfos, nlsCreditInfoVo);
			list = (List<NlsCreditInfoVO>) beansCopy(nlsCreditInfos, NlsCreditInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	/**
	 * 根据用信bd_transaction_id查询对应的授信申请: <br>
	 *
	 * 0.1:caoxin:2019/6/10 8:11: <br>
	 * @author caoxin
	 * @return
	 * @since 2019/6/10 8:11
	 * @date 2019/6/10 8:11
	 * @version 0.1
	 */
	@Override
	public NlsCreditInfoVO queryByTransactionId(String transactionId) {
		logger.debug("当前查询参数信息为:"+ transactionId);
		try {
			NlsCreditInfo queryRslNlsCreditInfo = nlsCreditInfoDao.queryByTransactionId(transactionId);
			if (Objects.nonNull(queryRslNlsCreditInfo)) {
				NlsCreditInfoVO outNlsCreditInfoVo = beanCopy(queryRslNlsCreditInfo, new NlsCreditInfoVO());
				logger.debug("当前查询结果为:"+ outNlsCreditInfoVo.toString());
				return outNlsCreditInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}
/**
	 * 通过身份证号和身份证证件类型判断 一个用户是否存在多个授信: <br>
	 *
	 * 0.1:caoxin:2019/4/18 14:56: TODO: <br>
	 * @author caoxin
	 * @return
	 * @since 2019/4/18 14:56
	 * @date 2019/4/18 14:56
	 * @version 0.1
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<NlsCreditInfoVO> countPeopelHasCredits(NlsCreditInfoVO nlsCreditInfoVO) {
		logger.debug("统计某个身份证号是否有多个授信");
		NlsCreditInfo nlsCreditInfo = new NlsCreditInfo();
		List<NlsCreditInfoVO> nlsCreditInfoVOS = new ArrayList<>();
		try {
			beanCopy(nlsCreditInfoVO,nlsCreditInfo);
			List<NlsCreditInfo> nlsCreditInfos = nlsCreditInfoDao.countPeopelHasCredits(nlsCreditInfo);
			nlsCreditInfoVOS = (List<NlsCreditInfoVO>)beansCopy(nlsCreditInfos, NlsCreditInfoVO.class);
		} catch (Exception e) {
			logger.error("统计某个身份证号是否有多个授信转换出现异常!", e);
		}
		return nlsCreditInfoVOS;
	}
	/**
	 * 
	 * TODO <br>
	 * 0.1:wanglihua:2019年4月19日 下午5:48:44:TODO <br>
	 * @author wanglihua
	 * @since 2019年4月19日 下午5:48:44
	 * @date 2019年4月19日 下午5:48:44
	 * @version 0.1 初始为0.1,后续变更则修改
	 */
	public NlsCreditInfoVO queryContractEle(NlsCreditInfoVO nlsCreditInfoVO) {
		logger.debug("当前查询参数信息为:"+ nlsCreditInfoVO.toString());
		try {
			NlsCreditInfo queryNlsCreditInfo = new NlsCreditInfo();
			beanCopy(nlsCreditInfoVO, queryNlsCreditInfo);
			NlsCreditInfo queryRslNlsCreditInfo = nlsCreditInfoDao.queryContractEle(queryNlsCreditInfo);
			if (Objects.nonNull(queryRslNlsCreditInfo)) {
				NlsCreditInfoVO outNlsCreditInfoVo = beanCopy(queryRslNlsCreditInfo, new NlsCreditInfoVO());
				logger.debug("当前查询结果为:"+ outNlsCreditInfoVo.toString());
				return outNlsCreditInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	@Override
	public NlsCreditInfoVO queryByLmtApplySeq(String lmtApplySeq) {
		logger.debug("当前查询参数信息为:"+ lmtApplySeq);
		try {
			NlsCreditInfo queryRslNlsCreditInfo = nlsCreditInfoDao.queryByLmtApplySeq(lmtApplySeq);
			if (Objects.nonNull(queryRslNlsCreditInfo)) {
				NlsCreditInfoVO outNlsCreditInfoVo = beanCopy(queryRslNlsCreditInfo, new NlsCreditInfoVO());
				logger.debug("当前查询结果为:"+ outNlsCreditInfoVo.toString());
				return outNlsCreditInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		return null;
	}

	@Override
	public int updateAmtByApplySeq(NlsCreditInfoVO nlsCreditInfoVO) {
		logger.debug("当前修改数据为:"+ nlsCreditInfoVO.toString());
		int num = 0;
		try {
			NlsCreditInfo nlsCreditInfo = new NlsCreditInfo();
			beanCopy(nlsCreditInfoVO, nlsCreditInfo);
			num = nlsCreditInfoDao.updateAmtByApplySeq(nlsCreditInfo);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ nlsCreditInfoVO +"修改的数据条数为"+ num);
		return num;
	}

	/**
	 * 
	 * TODO 将审批状态更新为拒绝<br>
	 * @author wanglihua
	 * @since 2019年5月8日 下午7:25:04
	 * @date 2019年5月8日 下午7:25:04
	 * @version 0.1 
	 */
	@Override
	public int updateApprvSts(String apprvSts, String applySeq) {
		logger.debug("当前修改数据的流水号为:"+ applySeq);
		int num = 0;
		try {
			num = nlsCreditInfoDao.updateApprvSts(apprvSts,applySeq);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ applySeq +"修改的数据条数为"+ num);
		return num;
	}

	@Override
	public List<NlsCreditInfoVO> getNeedUploadList(Integer recordsNum, String bizType,String prdId) {
		List<NlsCreditInfo> needUploadList = this.nlsCreditInfoDao.getNeedUploadList(recordsNum, bizType,prdId);
		try {
			return (List<NlsCreditInfoVO>) beansCopy(needUploadList,NlsCreditInfoVO.class);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("转换数据出错");
		}
		return null;
	}

	@Override
	public List<NlsCreditInfoVO> getFourElementsIfNullList(String prdId) {
		List<NlsCreditInfo> needUploadList = this.nlsCreditInfoDao.getFourElementsIfNullList(prdId);
		try {
			return (List<NlsCreditInfoVO>) beansCopy(needUploadList,NlsCreditInfoVO.class);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("转换数据出错");
		}
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<NlsCreditInfoVO> getCreditsBycust(NlsCreditInfoVO nlsCreditInfoVO) {
		List<NlsCreditInfoVO> result = null;
		logger.debug("查询条件信息为：" + JSON.toJSONString(nlsCreditInfoVO));
		try {
			NlsCreditInfo nlsCreditInfo = beanCopy(nlsCreditInfoVO, new NlsCreditInfo());
			List<NlsCreditInfo> nlsCreditInfos = nlsCreditInfoDao.getCreditsBycust(nlsCreditInfo);
			logger.debug("查询结果集数量为："+ nlsCreditInfos.size());
			result = (List<NlsCreditInfoVO>) beansCopy(nlsCreditInfos, NlsCreditInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return result;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<NlsCreditInfoVO> queryAllByCurrentDate(NlsCreditInfoVO nlsCreditInfoVO) {
		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<NlsCreditInfoVO> list = null;
		try {
			List<NlsCreditInfo> nlsCreditInfos = nlsCreditInfoDao.queryAllByCurrentDate(nlsCreditInfoVO);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ nlsCreditInfos.size());
			list = (List<NlsCreditInfoVO>) beansCopy(nlsCreditInfos, NlsCreditInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}


	@Override
	public boolean batchUpdateCusManage(List<SedSynCusManageVO> sedSynCusManageVOList){
		logger.info("批量更新客户经理开始" );
		boolean result = false;
		try {
			@SuppressWarnings("unused")
			List<SedSynCusManageVO> list = new ArrayList<SedSynCusManageVO>();//
			@SuppressWarnings("unused")
			int num = nlsCreditInfoDao.batchUpdateCusManage(sedSynCusManageVOList);
			result =true;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("客户经理变更更新台账表出错!", e);
		}
		return result;
	}

	@Override
	public NlsCreditInfoVO queryByCondition(NlsCreditInfoVO nlsCreditInfoVo) {
		logger.debug("当前查询参数信息为："+ nlsCreditInfoVo);
		try {
			NlsCreditInfo queryNlsCreditInfo = new NlsCreditInfo();
			beanCopy(nlsCreditInfoVo, queryNlsCreditInfo);
			NlsCreditInfo queryRslNlsCreditInfo = nlsCreditInfoDao.queryByCondition(queryNlsCreditInfo);
			if (Objects.nonNull(queryRslNlsCreditInfo)) {
				NlsCreditInfoVO outNlsCreditInfoVo = beanCopy(queryRslNlsCreditInfo, new NlsCreditInfoVO());
				logger.debug("当前查询结果为:"+ outNlsCreditInfoVo.toString());
				return outNlsCreditInfoVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 需求编号：【额度管控】
	 * 问题编号：【根据授信有效期更新授信状态为失效】
	 * 开发人员：【chenxuan】
	 * 创建/修改日期：【2019/9/3】
	 * 修改描述：
	 * @Param []
	 * @return int
	 **/
	@Override
	public int inValidLmtProContOverExpireDate(String openDay) {
		LocalDate date = LocalDate.now();
		String msg1 = "开始失效超过授信协议到期的记录..."+date;
		logger.debug(msg1,"message {}");
		int num = 0;
		try {
			num = nlsCreditInfoDao.inValidLmtProContOverExpireDate(openDay);
		} catch (Exception e) {
			String msg2 = "失效超过授信协议到期的记录发生错误" + e;
			num = -1;
			logger.error(msg2,"message {}");
		}
		return num;
	}

	@Override
	public List<NlsCreditInfoVO> queryAllByConditionPage(NlsCreditInfoVO nlsCreditInfoVO) {
		List<NlsCreditInfoVO> list = null;
		logger.debug("当前查询数据信息的参数信息为:");
		List<NlsCreditInfo> nlsCreditInfos = nlsCreditInfoDao.queryAllByConditionByPage(nlsCreditInfoVO);
		logger.debug("当前产品种类数据信息的结果集数量为:"+ nlsCreditInfos.size());
		try {
			pageSet(nlsCreditInfos, nlsCreditInfoVO);
			list = (List<NlsCreditInfoVO>) beansCopy(nlsCreditInfos, NlsCreditInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	@Override
	public List<NlsCreditInfoVO> getCusManagerRecord(String prdId,String orgCode) throws BizException {
		List<NlsCreditInfoVO> nlsCreditInfoVOs = null;
		try {
			List<NlsCreditInfo> cusManagerRecord = nlsCreditInfoDao.getCusManagerRecord(prdId,orgCode);
			nlsCreditInfoVOs = (List<NlsCreditInfoVO>) beansCopy(cusManagerRecord, NlsCreditInfo.class);
		} catch (Exception e) {
			e.printStackTrace();
			throw new BizException("查询客户经理记录出现异常");
		}
		return nlsCreditInfoVOs;
	}

	@Override
	public NlsCreditInfoVO queryByPrdSeq(String preLmtApplySeq) {
		return beanCopy(nlsCreditInfoDao.queryByPrdSeq(preLmtApplySeq),new NlsCreditInfoVO());
	}

	/**
	 *需求编号：【2019D1218】（普税贷需求）
	 *问题编号：【2019D1218】（普税贷查询审批日期区间授信信息）
	 *开发人员：【ludayong】
	 *创建日期：【2020/3/18 12:26】
	 *功能描述：
	 *修改日期：【2020/3/18 12:26】
	 *修改描述：
	 */
	@Override
	public List<NlsCreditInfoVO> queryPsdBtApprvDateByPage(NlsCreditInfoVO nlsCreditInfoVO) {
		String msg1 = "【普税贷】查询审批日期区间授信信息";
		logger.debug(msg1, "message {}");
		List<NlsCreditInfoVO> list = null;
		try {
			List<NlsCreditInfo> bdMoneyDrawTemps = nlsCreditInfoDao.queryPsdBtApprvDateByPage(nlsCreditInfoVO);
			list = (List<NlsCreditInfoVO>) beansCopy(bdMoneyDrawTemps, NlsCreditInfoVO.class);
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		if(list != null) {
			String msg2 = "查询的数据为大小为 " + list.size();
			logger.debug(msg2, "message {}");
		}
		return list;
	}

	/**
	 *需求编号：【2019D1218】（普税贷需求）
	 *问题编号：【2019D1218】（普税贷查询审批日期区间授信信息统计数据量）
	 *开发人员：【ludayong】
	 *创建日期：【2020/3/18 12:27】
	 *功能描述：
	 *修改日期：【2020/3/18 12:27】
	 *修改描述：
	 */
	@Override
	public int queryPsdBtApprvDateCount(NlsCreditInfoVO nlsCreditInfoVO) {
		String msg1 = "【普税贷】查询审批日期区间授信信息数据量";
		logger.debug(msg1, "message {}");
		int num = 0;
		try {
			num = nlsCreditInfoDao.queryPsdBtApprvDateCount(nlsCreditInfoVO);
		} catch (Exception e) {
			String msg2 = "【普税贷】查询审批日期区间授信信息数据量出错" + e;
			logger.debug(msg2, "message {}");
			num = -1;
		}
		return num;
	}

    @Override
    public List<NlsCreditInfoVO> selectByGlobalSerno(NlsCreditInfoVO nlsCreditInfoVO) {
        try {
            return (List<NlsCreditInfoVO>)beansCopy((nlsCreditInfoDao.selectByGlobalSerno(beanCopy(nlsCreditInfoVO, new NlsCreditInfo()))),NlsCreditInfoVO.class);
        } catch (Exception e) {
            logger.error("【授信申请基本信息】插入或更新数据出现异常:", e);
        }
        return null;
    }

	@Override
	public List<NlsCreditInfoVO> selectByGmAndCertCode(String gm, String certCode) throws Exception {
		return (List<NlsCreditInfoVO>)beansCopy(nlsCreditInfoDao.selectByGmAndCertCode(gm,certCode),NlsCreditInfoVO.class);
	}

	@Override
	public List<NlsCreditInfoVO> queryByCucCodeAndPrdId(NlsCreditInfoVO nlsCreditInfoVO) throws Exception {
		return (List<NlsCreditInfoVO>) beansCopy(nlsCreditInfoDao.queryCertCode(nlsCreditInfoVO), NlsCreditInfoVO.class);
	}

	/**
	 * 根据预授信流水号查询授信申请记录
	 * @param preLmtApplySeq
	 * @return
	 */
	@Override
	public List<NlsCreditInfoVO> queryByPreLmtApplySeq(String preLmtApplySeq) {
		String msg1 = "【普税贷】查询审批日期区间授信信息";
		logger.debug(msg1, "message {}");
		List<NlsCreditInfoVO> list = null;
		try {
			List<NlsCreditInfo> nlsCreditInfoList = nlsCreditInfoDao.queryByPreLmtApplySeq(preLmtApplySeq);
			list = (List<NlsCreditInfoVO>) beansCopy(nlsCreditInfoList, NlsCreditInfoVO.class);
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		if(list != null) {
			String msg2 = "查询的数据为大小为 " + list.size();
			logger.debug(msg2, "message {}");
		}
		return list;
	}

	@Override
	public BigDecimal queryArroveLimitTotal(String prdId) {
		return this.nlsCreditInfoDao.queryArroveLimitTotal(prdId);
	}

    @Override
    public List<NlsCreditInfoVO> queryInPreLmtApplySeq(List<String> list) throws Exception {
            return (List<NlsCreditInfoVO>) beansCopy(nlsCreditInfoDao.queryInPreLmtApplySeq(list), NlsCreditInfoVO.class);
    }

	public int queryCreditOnWay(NlsCreditInfoVO nlsCreditInfoVO){

		logger.debug("查询条件信息为：" + JSON.toJSONString(nlsCreditInfoVO));
		int count=0;
		try {
			NlsCreditInfo nlsCreditInfo = beanCopy(nlsCreditInfoVO, new NlsCreditInfo());
			count = nlsCreditInfoDao.getCreditsByCondition(nlsCreditInfo);
			logger.debug("查询结果集数量为："+ count);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return count;
	}

		@Override
		public List<NlsCreditInfoVO> queryCreditDuring(String certType,String certCode,String prdId,String applySeq) {
		List<NlsCreditInfoVO> list = new ArrayList<>();
		logger.debug("当前查询数据信息的参数信息为:");
		List<NlsCreditInfo> nlsCreditInfos = nlsCreditInfoDao.queryCreditDuring( certType, certCode,prdId,applySeq);
		logger.debug("当前在途授信结果集数量为:"+ nlsCreditInfos.size());
		try {
			list = (List<NlsCreditInfoVO>) beansCopy(nlsCreditInfos, NlsCreditInfoVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	public int updateAcctNo(NlsCreditInfoVO nlsCreditInfoVO){
		NlsCreditInfo nlsCreditInfo = new NlsCreditInfo();
		nlsCreditInfo.setCertCode(nlsCreditInfoVO.getCertCode());
		nlsCreditInfo.setPrdId(nlsCreditInfoVO.getPrdId());
		nlsCreditInfo.setRecvAccount(nlsCreditInfoVO.getRecvAccount());
		logger.debug("当前修改信息的参数信息为:"+ nlsCreditInfo);
		int num = nlsCreditInfoDao.updateAcctNo(nlsCreditInfo);
		return num;
	}
}

